﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace CVS_log_parser
{
    public class CvsFileRevision : CvsFileRevisionBase
    {
        internal CvsFileRevision( string rawString, CvsFileInfo parent )
        {
            this.ParentFileInfo = parent;
            var iFileName = rawString.IndexOf( "filename:" );
            var comment = rawString.Substring( rawString.IndexOf( ';', iFileName == -1 ? 0 : iFileName ) );

            rawString = rawString.Replace( comment, "" );
            comment = comment.TrimStart( ( ";" + Environment.NewLine ).ToCharArray() );

            var props = new PropsDictionary( rawString );

            this.Revision = props.GetValue( "Revision", " " );
            this.Date = DateTime.Parse( props["Date"] );
            this.Author = props["Author"];
            this.State = props["State"];
            this.Kopt = props["Kopt"];
            this.CommitId = 0;// long.Parse( string.IsNullOrEmpty( props["CommitId"] ) ? "0x0" : props["CommitId"], NumberStyles.HexNumber );
            this.FileName = props["FileName"];
            this.Comment = comment;
        }

        public override string ToString()
        {
            return this.Revision;
        }

        public CvsFileInfo ParentFileInfo { get; private set; }
    }
}
